package graphic;

import graphic.mycomponents.ToolBarDialogClassNavigationButton;

import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;

import javax.swing.JToolBar;

public class ToolBar extends JToolBar {

	protected static ToolBar TOOLBAR;
	
	public static LinkedList<String> ONLY_RUN;
	public static LinkedList<String> ONLY_STOP;
	
	HashMap<String, ToolBarDialogClassNavigationButton> buttons;
	
	public ToolBar()
	{
		ToolBar.instanceStaticVars();
		
		this.buttons = new HashMap<String, ToolBarDialogClassNavigationButton>();
		
		this.addServerButtons();
		super.addSeparator();
		this.serverAddingButtons();
		super.addSeparator();
		this.addSingleProgramButton();
		
		this.disableAllButtonsInsteadOf(new LinkedList<String>());
	}

	public void enableAllButtonsInsteadOf(LinkedList<String> notEnable)
	{
		for (Iterator iterator = this.buttons.keySet().iterator(); iterator.hasNext();) {
			String buttonName = (String) iterator.next();
			
			if(notEnable.contains(buttonName))
				this.buttons.get(buttonName).setEnabled(false);
			else
				this.buttons.get(buttonName).setEnabled(true);
		}
	}
	
	public void disableAllButtonsInsteadOf(LinkedList<String> notDisable)
	{
		for (Iterator iterator = this.buttons.keySet().iterator(); iterator.hasNext();) {
			String buttonName = (String) iterator.next();
			
			if(notDisable.contains(buttonName))
				this.buttons.get(buttonName).setEnabled(true);
			else
				this.buttons.get(buttonName).setEnabled(false);
		}
	}
	
	protected void addServerButtons()
	{
		ToolBarDialogClassNavigationButton button;
		
		button = new ToolBarDialogClassNavigationButton("run.jpg", "graphic.dialogs.ServerLoginDialog", "Create a New User", "New User");
		this.buttons.put("run", button);
		super.add(button);

		button = new ToolBarDialogClassNavigationButton("stop.jpg", "graphic.dialogs.ServerStopDialog", "Add a New Program", "New Program");
		this.buttons.put("stop", button);
		super.add(button);
		
		button = new ToolBarDialogClassNavigationButton("serverSettings.jpg", "graphic.dialogs.ServerConfigurationDialog", "Change Server Settings", "Server Settings");
		this.buttons.put("serverSettings", button);
		super.add(button);
	}

	protected void serverAddingButtons()
	{
		ToolBarDialogClassNavigationButton button;
		
		button = new ToolBarDialogClassNavigationButton("user.jpg", "graphic.dialogs.NewUserDialog", "Create a New User", "New User");
		this.buttons.put("user", button);
		super.add(button);
		
		button = new ToolBarDialogClassNavigationButton("userList.jpg", "graphic.dialogs.UserListDialog", "User List", "Show User List");
		this.buttons.put("userList", button);
		super.add(button);
		
		button = new ToolBarDialogClassNavigationButton("program.jpg", "graphic.dialogs.NewProgramDialog", "Add a New Program", "New Program");
		this.buttons.put("program", button);
		super.add(button);
		
		button = new ToolBarDialogClassNavigationButton("programList.jpg", "graphic.dialogs.ProgramListDialog", "Program List", "Show Program List");
		this.buttons.put("programList", button);
		super.add(button);
		
		button = new ToolBarDialogClassNavigationButton("programToUser.jpg", "graphic.dialogs.NewProgramToUserDialog", "Associate Programs to Users", "Users and Programs Associations");
		this.buttons.put("programToUser", button);
		super.add(button);
	}
	
	protected void addSingleProgramButton()
	{
		ToolBarDialogClassNavigationButton button;
		
		button = new ToolBarDialogClassNavigationButton("newFile.jpg", "graphic.dialogs.NewFileDialog", "Create a New File", "New File");
		this.buttons.put("newFile", button);
		super.add(button);

		button = new ToolBarDialogClassNavigationButton("deleteFile.jpg", "graphic.dialogs.DeleteFileDialog", "Delete a File", "delete File");
		this.buttons.put("deleteFile", button);
		super.add(button);
		
		button = new ToolBarDialogClassNavigationButton("programSettings.jpg", "graphic.dialogs.ProgramSettingsDialog", "Change Program Settings", "Program Settings");
		this.buttons.put("programSettings", button);
		super.add(button);
	}
	
	public static void instanceStaticVars()
	{
		ONLY_RUN = new LinkedList<String>();
		ONLY_RUN.add("run");
		
		ONLY_STOP = new LinkedList<String>();
		ONLY_STOP.add("stop");		
	}
	
	public static synchronized ToolBar getInstance()
	{
		if(TOOLBAR == null) TOOLBAR = new ToolBar();
		return TOOLBAR;
	}
	
}